package com.cusc.module_login.mvvm.ui;


import android.view.View;

import androidx.lifecycle.ViewModelProvider;

import com.cusc.lib_api.bean.login.MainBean;
import com.cusc.module_login.BR;
import com.cusc.module_login.R;
import com.cusc.module_login.adapter.FunctionAdapter;
import com.cusc.module_login.databinding.ActFunctionBinding;
import com.cusc.module_login.factory.LoginViewModuleFactory;
import com.cusc.module_login.mvvm.vm.FunctionViewModel;
import com.tcgroup.phone.base_core.event.event_router.RouterPath;
import com.tcgroup.phone.base_core.framework.mvvm.activity.BaseMvvmRefreshActivity;
import com.tcgroup.phone.base_core.utils.ARouterUtils;
import com.tcgroup.phone.base_core.utils.ObservableListUtil;
import com.tcgroup.phone.base_core.widget.SSmartRefreshLayout;

import static com.cusc.module_login.R.layout;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/25.
 * 包名: com.cusc.module_login
 * 类名: OSAndroidMvvm
 */
public class FunctionActivity extends BaseMvvmRefreshActivity<ActFunctionBinding, FunctionViewModel> {

    FunctionAdapter mFunctionAdapter;

    @Override
    public SSmartRefreshLayout getRefreshLayout() {
        return mBinding.smartRefreshLayout;
    }

    @Override
    public int onBindVariableId() {
        return BR.model;
    }

    @Override
    public Class<FunctionViewModel> onBindViewModel() {
        return FunctionViewModel.class;
    }

    @Override
    public ViewModelProvider.Factory onBindViewModelFactory() {
        return LoginViewModuleFactory.getInstance(getApplication());
    }

    @Override
    public void initView() {
        super.initView();
        mFunctionAdapter = new FunctionAdapter(this,mViewModel.getList());
        mViewModel.getList().addOnListChangedCallback(ObservableListUtil.getListChangedCallback(mFunctionAdapter));
        mBinding.recyclerview.setAdapter(mFunctionAdapter);
        mFunctionAdapter.setItemClickListener((mainBean, position,style) -> {
            MainBean bean = (MainBean) mainBean;
            if (bean.getModelName().equals(getString(R.string.module_login_apply))){
                ARouterUtils.navigation(RouterPath.Apply_Router.Apply_ACT_Main,FunctionActivity.this);
                return;
            }
            if (bean.getModelName().equals(getString(R.string.module_login_monitor))){
                ARouterUtils.navigation(RouterPath.Location_Monitor_Router.Location_Monitor_Main,FunctionActivity.this);
                return;
            }
        });
        getRefreshLayout().autoRefresh();
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public void initViewObservable() {

    }

    @Override
    public void onRetryBtnClick() {

    }

    @Override
    public void onBackPressedClick() {

    }

    @Override
    public int onBindLayout() {
        return layout.act_function;
    }

    @Override
    public Object bindLoadSir() {
        return null;
    }

    @Override
    public void initImmersionBar(View view) {
        super.initImmersionBar(view);

    }
}
